using NaughtyAttributes;
using UnityEngine;

namespace Gj
{
    public class DragHelper : NodeHelper
    {
        public bool invert;
        private Vector3 p;
        private bool allow;
        protected override BindDataType bindDataType => BindDataType.Bool;
        protected override void Start()
        {
            p = transform.position;
        }

        private void Update()
        {
            if (!allow) return;
            Refresh();
        }

        protected override void BindData(bool b)
        { 
            allow = invert ? !b : b;
            if (!allow)
            {
                transform.position = p;
            }
            else
            {
                Refresh();
            }
        }

        void Refresh()
        {
            transform.position = SystemInput.cp;
            Emit(UIEvent.Drag);
        }
    }
}